﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Meraz.Core.Model;
using System.Xml;

namespace Meraz.Core.Parsers
{
    public abstract class XmlBlogParser : BlogParserBase
    {
        public override PostValues Parse(string permalink, string source)
        {
            PostValues post = new PostValues();
            post.Permalink = permalink;
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(source);
            post.Title = CollapseWhitespace(doc.SelectSingleNode("/html/head/title").InnerText);
            post.Body = GetBody(doc);
            post.Aliases = GetAliases(doc);
            post.Links = ParseLinks(post.Body);
            post.Links.Remove(permalink);
            post.Pubdate = GetPubDate(doc);
            post.BlogName = this.BlogKey.ToString();
            return post;
        }

        internal abstract List<string> GetAliases(XmlDocument doc);
        internal abstract string GetBody(XmlDocument doc);
        internal abstract DateTime GetPubDate(XmlDocument doc);
    }
}
